package com.imooc.spark.streaming.operateTest

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
  * @description map flatmap区分
  * @author yuyon26@126.com
  * @date 2018/10/24 10:39
  */
object Map_FlatMap {
  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[2]").setAppName("NetworkWordCount")
    val ssc = new StreamingContext(sparkConf, Seconds(5))
    ssc.sparkContext.setLogLevel("ERROR")

    val lines = ssc.socketTextStream("192.168.31.30", 9999)
    val mapLines = lines.map(_.split(" "))
    val fmapLines = lines.flatMap(_.split(" "))

    mapLines.print()
    mapLines.foreachRDD(rdd=>{
      rdd.foreach(record=>{
        record.foreach(x=>{
          println(x)
        })
      })
    })
    fmapLines.print()

    ssc.start()
    ssc.awaitTermination()
  }
}
